package com.fhz.a2102shopjava.interceptor;

import com.blankj.utilcode.util.SPUtils;
import com.tencent.mmkv.MMKV;

import java.io.IOException;

import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * 时间:2023/8/15
 *
 * @author Mr.Feng
 * 简述: TODO
 */
public class TokenInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request original = chain.request();
        //根据不盘的url 判断是不是要加入token
//        HttpUrl url = original.url(); //base he api
//        String token = SPUtils.getInstance().getString(SPUtils.TOKEN, "");

        MMKV mmkv = MMKV.defaultMMKV();
        String token = mmkv.getString("token", "");
        Request.Builder requestBuilder = original.newBuilder().header("Authorization", token);
        Request request = requestBuilder.build();
        return chain.proceed(request);
    }
}
